#include <cstdint>
#include <iostream>
#include <queue>
#include <vector>

using ll = int64_t;
using vl = std::vector<ll>;
#define N(v)#v<<" :"<<(v)<<" "
auto &ci = std::cin;
auto &co = std::cout;

const ll max_n = 5e4+5;
ll *sn = new ll[max_n];
auto *nds = new vl[max_n];

void dfs(ll ft, ll n){
    sn[n]=1;
    if(nds[n].size()==1 && nds[n][0]==ft){
        return;
    }
    for(ll i:nds[n]){
        if(i==ft){
            continue;
        }
        dfs(n, i);
        sn[n]+=sn[i];
    }
    return;
}

int main(){
    ll n;
    ci>>n;
    for(ll i{1}; i<n; i++){
        ll a, b;
        ci>>a>>b;
        nds[a].push_back(b);
        nds[b].push_back(a);
    }
    dfs(0, 1);
    
    ll now{1};
    ll nxt{}, nn{-1};
    ll f{1};
    for(ll i:nds[now]){
        if(sn[i]>nn && i!=now){
            nn = sn[i];
            nxt = i;
        }
    }
    co<<"nxt: "<<nxt<<" now: "<<now<<"\n";
    ll t{sn[1]-sn[nxt]};
    ll b{sn[nxt]-1};
    
    // ll fsn{sn[1]};
    // co<<"t "<<t<<" b "<<b<<'\n';
    ll ft{t}, fb{b};
    while(t<b){
        if(nds[now].size()==0)break;
        f = now;
        now = nxt;
        nn = -1;
        for(ll i{0}; i<nds[now].size(); i++){
            for(ll i:nds[now]){
                if(sn[i]>nn && i!=f){
                    nn = sn[i];
                    nxt = i;
                }
            }
        }
        ft=t, fb = b;
        t+=(sn[now]-sn[nxt]);
        b = sn[nxt]-1;
        co<<"now: "<<now<<" nxt:"<<nxt<<" t: "<<t<<" b:"<<b<<'\n';
    }

    // co<<N(ft)<<N(fb)<<N(now)<<N(nxt)<<'\n';
    
}